package com.lcz.study_designmode.结构型模式.组合模式;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 * <img width="128" height="110" src="https://tse3-mm.cn.bing.net/th/id/OIP-C.en-w_oH-yn2UsSRfWnOsGAHaGY?w=198&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7" alt="马刺">
 * 作者:     <a href="https://github.com/liuchuanzheng">刘传政</a>
 * 创建时间:  10:41 2022/6/8 0008
 * QQ:      1052374416
 * 电话:     18501231486
 * 描述:
 * </pre>
 */
public class Menu extends MenuComponent {
    private List<MenuComponent> menuComponentList = new ArrayList<>();

    public Menu(String name, int level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void add(MenuComponent menuComponent) {
        menuComponentList.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponentList.remove(menuComponent);
    }

    @Override
    public MenuComponent getChild(int index) {
        return menuComponentList.get(index);
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public void print() {
        for (int i = 0; i < level; i++) {
            System.out.print("-");
        }
        //打印菜单
        System.out.println(name);
        //打印内容
        for (MenuComponent menuComponent : menuComponentList) {
            menuComponent.print();
        }
    }
}
